package com.bw.kotlindemo.java.vm;

import android.app.Application;
import android.util.Log;

import androidx.annotation.NonNull;
import androidx.lifecycle.MutableLiveData;

import com.bw.kotlindemo.java.base.BaseViewModel;
import com.bw.kotlindemo.java.model.bean.LiveListBean;
import com.bw.kotlindemo.java.model.bean.TypeBean;
import com.bw.kotlindemo.java.model.net.RetrofitManager;
import com.bw.kotlindemo.kotlin.model.KRetrofitManager;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * desc:
 * create by xushaodong on 2023/4/4
 */
public class LiveVM extends BaseViewModel {
    public MutableLiveData<String> errorVM = new MutableLiveData<>();
    public MutableLiveData<TypeBean> liveTypeData = new MutableLiveData<TypeBean>();
    public MutableLiveData<LiveListBean> liveListVM = new MutableLiveData<>();

    public LiveVM(@NonNull Application application) {
        super(application);
    }

    /***
     * 获取直播type列表
     */
    public void getTypeList() {
        RetrofitManager.getInstance()
                .getApiService()
                .getListType()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<TypeBean>() {
                    @Override
                    public void accept(TypeBean typeBean) throws Exception {
                        liveTypeData.setValue(typeBean);
                    }
                });
    }

    /**
     * 获取直播列表
     */
    public void loadLiveList(int liveType, int page, int size) {
        showLoadingVM.setValue(true);
        RetrofitManager.getInstance()
                .getApiService().getLiveByType(liveType, page, size)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<LiveListBean>() {
                    @Override
                    public void accept(LiveListBean homeListBean) throws Exception {
                        //处理网络数据
                        liveListVM.setValue(homeListBean);
                    }
                });


    }
}
